import { ipcRenderer } from 'electron-better-ipc'
import { IWorkSpaceData } from './interfaces'

// 默认工作空间数据
export const getDefaultWorkSpaceData = (id: string, path: string) => {
    return ipcRenderer.callMain<{ id: string; path: string }, IWorkSpaceData>('getDefaultWorkSpaceData', { id, path })
}

// 创建工作空间数据
export const createWorkSpace = (path: string) => {
    return ipcRenderer.callMain<string, string>('createWorkSpace', path)
}

// 根据目录获取工作空间id
export const getWorkSpaceId = (path: string) => {
    return ipcRenderer.callMain<string, string>('getWorkSpaceId', path)
}

// 读取工作空间数据
export const readWorkSpaceData = (id: string) => {
    return ipcRenderer.callMain<string, IWorkSpaceData>('readWorkSpaceData', id)
}

// 保存工作空间数据
export const saveWorkSpaceData = (params: { id: string; data: IWorkSpaceData }) => {
    return ipcRenderer.callMain<{ id: string; data: IWorkSpaceData }, void>('saveWorkSpaceData', params)
}

export const openWorkSpace = (path: string) => {
    return ipcRenderer.callMain<string, IWorkSpaceData>('openWorkSpace', path)
}
